home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-07-08 | 1.9 KB | 76 lines | [TEXT/MMCC] |
- /*
- Copyright © 1993,1994 by Fabrizio Oddone
- ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
- This source code is distributed as freeware: you can copy, exchange, modify this
- code as you wish. You may include this code in any kind of application: freeware,
- shareware, or commercial, provided that full credits are given.
- You may not sell or distribute this code for profit.
- */
-
- //#pragma load "MacDump"
-
- #include "TrackThumb.h"
-
- //#pragma segment Main
-
- /*
- TrackThumb must be called as follows:
- partCode = TrackThumb(whichControl, localPoint, actionProc);
-
- actionProc must be declared as follows:
- pascal void actionProc(ControlHandle control, short value);
- */
-
- short TrackThumb(ControlHandle control, Point start, void (*action)(ControlHandle, short))
- {
- enum {
- kTooDistant = 23
- };
-
- EventRecord dummyEventRec;
- Rect rct;
- GrafPtr savePort;
- Point pos;
- register long val, new;
- register short min, max, old, widthOrheight;
-
- GetPort(&savePort);
- SetPort((*control)->contrlOwner);
- min = GetCtlMin(control); /* min value */
- max = GetCtlMax(control); /* max value */
- val = GetCtlValue(control); /* cur value */
- rct = (*control)->contrlRect; /* control's rectangle */
-
- widthOrheight = rct.right - rct.left;
- old = -32768;
- do {
- GetMouse(&pos);
-
- if (pos.v < rct.top + widthOrheight)
- pos.v = rct.top + widthOrheight;
- else if (pos.v > rct.bottom - widthOrheight)
- pos.v = rct.bottom - widthOrheight;
- new = val + (long)(max - min) * (pos.v - start.v) /
- (rct.bottom - rct.top - (widthOrheight * 3));
- if (new < min)
- new = min;
- if (new > max)
- new = max;
- if ((pos.h - rct.right > kTooDistant) || (rct.left - pos.h > kTooDistant))
- new = val;
-
- if (new != old) {
- SetCtlValue(control, new);
- action(control, old = GetCtlValue(control));
- }
- else { /* give some time to other applications */
- SystemTask();
- (void)EventAvail(everyEvent, &dummyEventRec);
- }
- }
- while(StillDown());
- SetPort(savePort);
- return inThumb;
- }
-
-